package com.ruoyi.project.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.project.system.domain.Course;
import com.ruoyi.project.system.domain.CourseCatalog;
import com.ruoyi.project.system.mapper.CourseCatalogMapper;
import com.ruoyi.project.system.mapper.CourseMapper;
import com.ruoyi.project.system.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 课程Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@Service
public class CourseServiceImpl implements ICourseService
{
    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseCatalogMapper courseCatalogMapper;

    /**
     * 查询课程
     * 
     * @param id 课程ID
     * @return 课程
     */
    @Override
    public Course selectCourseById(Integer id)
    {
        return courseMapper.selectCourseById(id);
    }

    /**
     * 查询课程列表
     * 
     * @param course 课程
     * @return 课程
     */
    @Override
    public List<Course> selectCourseList(Course course)
    {
        return courseMapper.selectCourseList(course);
    }

    /**
     * 新增课程
     * 
     * @param course 课程
     * @return 结果
     */
    @Override
    public int insertCourse(Course course)
    {

        CourseCatalog courseCatalog = courseCatalogMapper.selectCourseCatalogById(course.getCourseCatalogId().intValue());
        course.setCourseCatalogName(courseCatalog.getName());
        return courseMapper.insertCourse(course);
    }

    /**
     * 修改课程
     * 
     * @param course 课程
     * @return 结果
     */
    @Override
    public int updateCourse(Course course)
    {
        return courseMapper.updateCourse(course);
    }

    /**
     * 批量删除课程
     * 
     * @param ids 需要删除的课程ID
     * @return 结果
     */
    @Override
    public int deleteCourseByIds(Integer[] ids)
    {
        return courseMapper.deleteCourseByIds(ids);
    }

    /**
     * 删除课程信息
     * 
     * @param id 课程ID
     * @return 结果
     */
    @Override
    public int deleteCourseById(Integer id)
    {
        return courseMapper.deleteCourseById(id);
    }

    @Override
    public List<Map<String,Object>> selectCouresCatalog() {
        return courseCatalogMapper.selectCouresCatalog();
    }
}
